import request from "@/utils/request";
import {Ref, UnwrapRef} from "vue";

export const getBlogList = (currentPage: Ref<UnwrapRef<number>, UnwrapRef<number> | number>, pageSize: Ref<UnwrapRef<number>, UnwrapRef<number> | number>) => {
    return request({
        url: '/post/list',
        method: 'post',
        data: {
            currentPage,
            pageSize,
            sortField: "id",
            sortOrder: "ascend"
        }
    })
}

export const createBlog = (title: string, content: string, tags: string[], coverImage: string, userId: number) => {
    return request({
        url: '/post/create',
        method: 'post',
        data: {
            title: title,
            content: content,
            tags: tags,
            coverImage: coverImage,
            userId: userId
        }
    })
}

export const getBlog = (id:number) => {
    return request({
        url: '/post/get',
        method: 'post',
        params: {
            id
        }
    })
}

export const getCommentList = (id:number) => {
    return request({
        url: '/post/get/comment',
        method: 'post',
        params: {
            id
        }
    })
}

export const onComment = (postId: number, userId: number, text: string) => {
    return request({
        url: '/post/comment',
        method: 'post',
        params: {
            postId,
            userId,
            text
        }
    })
}

export const toThumb = (postId:number, userId: number) => {
    return request({
        url: '/post/thumb',
        method: 'post',
        data: {
            postId,
            userId
        }
    })
}

export const toFavour = (postId:number, userId: number) => {
    return request({
        url: '/post/favour',
        method: 'post',
        data: {
            postId,
            userId
        }
    })
}

export const favourStatus = (postId:number, userId: number) => {
    return request({
        url: '/post/favour/status',
        method: 'post',
        data: {
            postId,
            userId
        }
    })
}

export const thumbStatus = (postId:number, userId: number) => {
    return request({
        url: '/post/thumb/status',
        method: 'post',
        data: {
            postId,
            userId
        }
    })
}

